void Alarm()
{
  if(!showAlarm && menu == 0 && alarmSet && (alarmminutesLittle == minutesLittle && alarmminutesBig == minutesBig
    && alarmhoursLittle == hoursLittle && alarmhoursBig == hoursBig))
  {
    snooze = 0;
    alarmSoundVolume = alarmStartingVolume;
    alarmSoundFlop = true;
    alarmSoundTick = 0;
    alarmText = random(0, 6);
    showAlarmFlop = true;
    lastAlarmTick =  millis();
    showAlarm = true;
    ResetInputs();
  }
  if(showAlarm)
  {
    if(snooze <= 0)
    {
      AlarmSound();
    }
    if(leftActive || rightActive)
    {
      WriteTextAlways("SNOOZE", 5);
      Silence();// JUST FOR TESTING
      snooze = snoozeTime;
      ResetInputs();
    }
    if(shakeActive)
    {
      WriteTextAlways("ALARMM OFF", 9);
      ResetAlarm();
      ResetInputs();
    }
  }
}

void ResetAlarm()
{
  Silence();
  Serial.println("&&&&&&&&&&&&& RESET ALARM &&&&&&&&&&&");
  showAlarm = false;
  snooze = 0;
}

void Silence()
{
  alarmSoundVolume = alarmStartingVolume;
  alarmSoundFlop = true;
  alarmSoundTick = 0;
  digitalWrite(buzzerPin, LOW);
}

bool buzzerOn;
void AlarmSound()
{
  if(alarmSoundFlop)
  {
    alarmSoundCount ++;
    if(alarmSoundCount >= alarmSoundVolume)
    {
      alarmSoundCount = 0;
      digitalWrite(buzzerPin, buzzerOn);
      buzzerOn = !buzzerOn;
    }
  }
  
  if(alarmSoundTick == 0)
  {
    alarmSoundTick = millis();
  }
  else if (millis() - alarmSoundTick >=  alarmBeepRate) 
  {
    alarmSoundVolume --;
    alarmSoundTick =  millis();
    alarmSoundFlop = !alarmSoundFlop;
  }
}
